package com.jnxx.basic.util;

import com.alibaba.fastjson.JSONObject;
import com.jnxx.task.domain.OkrStaff;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.net.URLDecoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

// 在任意地方获取staff
public class GetStaffRequestUtil {

    public static OkrStaff getStaff() {
        OkrStaff staff = null;
        try {
            String token = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getHeader("token");
            String decode = URLDecoder.decode(token, "UTF-8");
            staff = JSONObject.parseObject(decode, OkrStaff.class);
        }catch (Exception e){
            e.printStackTrace();
        }
        return staff;
    }

    public static String getNowTime(){
        Date date = new Date();
        // 生成指定格式的时间字符串
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateTime = dateFormat.format(date);
        return dateTime;
    }
}
